package org.example.service.impl;

import net.bytebuddy.asm.Advice;
import org.example.domain.CarFile;
import org.example.domain.CarInfo;
import org.example.mapper.CarFileMapper;
import org.example.mapper.CarInfoMapper;
import org.example.service.CarInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarInfoServiceImpl implements CarInfoService {
    @Autowired
    CarInfoMapper carInfoMapper;
    @Autowired
    CarFileMapper carFileMapper;
    @Override
    public List<CarInfo> list(CarInfo carInfo) {
        return carInfoMapper.list(carInfo);
    }

    @Override
    public List<CarInfo> lists() {
        return carInfoMapper.lists();
    }

    @Override
    public void saveBatch(List<CarInfo> carInfoList) {
        carInfoMapper.saveBatch(carInfoList);
    }

    @Override
    public boolean add(CarInfo carInfo) {
        carInfoMapper.add(carInfo);
        List<CarFile> files = carInfo.getFiles();
        System.err.println(carInfo);
        if(files!=null && files.size()>0){
            for (CarFile file : files) {
                file.setCarId(carInfo.getCarId());
                file.setFileName(carInfo.getFiles()+"");
            }
            carFileMapper.saveZhong(files);
        }
        return true;
    }

    @Override
    public boolean update(CarInfo carInfo) {
        return carInfoMapper.update(carInfo);
    }

    @Override
    public boolean del(Integer carId) {
        return carInfoMapper.del(carId);
    }


}
